<?php

namespace App\Models;

class SpreadRecord extends Base
{
    //推广绑定
    public function bindAdd($data,$lang='zn'){
        try {
            $uid = (new User())->where('token',$data['token'])->value('id');
            if(!$uid){
                return [
                    'code'=>50000,
                    'message'=>$this->lang['LOGIN_EXPIRE'][$lang]
                ];
            }
            $spreuid = (new User())->where('spreadid',$data['spreadid'])->value('id');
            if(!$spreuid){
                return [
                    'code'=>1,
                    'message'=>$this->lang['SPRED_USER_NOT'][$lang]
                ];
            }
            $this->spreadid = $data['spreadid'];
            $this->uid = $uid;
            $res = $this->save();
            if($res){
                return [
                    'code'=>0,
                    'data'=>''
                ];
            }else{
                return [
                    'code'=>1,
                    'message'=>$this->lang['BIND_FAIL'][$lang]
                ];
            }
        }catch (\Exception $e){
            return [
                'code'=>1,
                'message'=>$this->lang['ERROR'][$lang]
            ];
        }
    }
}
